#include "StdAfx.h"
#include "LineObj.h"


CLineObj::CLineObj(void):CShape()
{
	m_shapeStyle = SHAPE_LINE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_width=0.5;
	m_bIsPoint=false;
	m_bIsStart=false;
	m_bIsMid=false;
	m_bIsEnd=false;
}


CLineObj::CLineObj( CEntityObj* pParentEnt ):CShape(pParentEnt)
{
	m_shapeStyle = SHAPE_LINE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_width=0.5;
	m_bIsPoint=false;
	m_bIsStart=false;
	m_bIsMid=false;
	m_bIsEnd=false;
}

CLineObj::CLineObj( const CLineObj* pSrc ):CShape(pSrc)
{
	m_shapeStyle = pSrc->getShapeStyle();

	m_dblStartPosX = pSrc->GetStartPosX();	
	m_dblStartPosY = pSrc->GetStartPosY();	
	m_dblEndPosX = pSrc->GetEndPosX();	
	m_dblEndPosY = pSrc->GetEndPosY();	
	m_dblR=pSrc->GetColorR();
	m_dblG=pSrc->GetColorG();
	m_dblB=pSrc->GetColorB();
	m_width=pSrc->GetWidth();
	m_bIsPoint=pSrc->GetIsPoint();
	m_bIsStart=pSrc->GetIsStart();
	m_bIsMid=pSrc->GetIsMid();
	m_bIsEnd=pSrc->GetIsEnd();
}

CLineObj::~CLineObj(void)
{
}

void CLineObj::Serialize( CArchive & ar )
{
	if (GetIsSvgGroundShape()||GetIsSvgComponentShape())
	{
		if (ar.IsStoring())
		{
			ar << m_dblStartPosX;	
			ar << m_dblStartPosY;	
			ar << m_dblEndPosX;	
			ar << m_dblEndPosY;	
			ar<<m_dblR;
			ar<<m_dblG;
			ar<<m_dblB;
			ar<<m_width;
			ar<<m_bIsPoint;
			if (CObj::m_lFileVersion>96)
			{
				ar<<m_bIsStart;
				ar<<m_bIsMid;
				ar<<m_bIsEnd;
			}
		} 
		else
		{
			ar >> m_dblStartPosX;	
			ar >> m_dblStartPosY;	
			ar >> m_dblEndPosX;	
			ar >> m_dblEndPosY;	
			ar >>m_dblR;
			ar >>m_dblG;
			ar >>m_dblB;
			ar >>m_width;
			ar >>m_bIsPoint;
			if (CObj::m_lFileVersion>96)
			{
				ar>>m_bIsStart;
				ar>>m_bIsMid;
				ar>>m_bIsEnd;
			}
		}
	}
	CShape::Serialize(ar);
}

double CLineObj::GetStartPosX() const
{
	return m_dblStartPosX;
}
double CLineObj::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CLineObj::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CLineObj::GetEndPosY() const
{
	return m_dblEndPosY;
}
void CLineObj::SetStartPosX(double posX)
{
	m_dblStartPosX = posX;
}

void CLineObj::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CLineObj::SetEndPosX(double posX)
{
	m_dblEndPosX = posX;
}

void CLineObj::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

CDisplayObj * CLineObj::CreateDisplayObj( long lLayerId )
{
	CLineDisplayObj *pLineDis = new CLineDisplayObj(this);
	pLineDis->SetLayerId(lLayerId);
	return pLineDis;
}


void CLineObj::CopyDisplayObj( long lSourceLayerId, long lDestLayerId )
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CLineObj::DeleteDisplayObj( long lLayerId )
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}



void CLineObj::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
}

void CLineObj::SetColor( double colorR, double colorG, double colorB )
{
	m_dblR = colorR;
	m_dblG = colorG;
	m_dblB = colorB;
}

CObj * CLineObj::Clone() const
{
	return new CLineObj(this);
}
